<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8" import="java.util.*"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<c:set var="path" value="${pageContext.request.contextPath }" />
<!DOCTYPE html>
<HTML>
<HEAD>
	<TITLE>功能分配</TITLE>
	<meta http-equiv="content-type" content="text/html; charset=UTF-8">
	<link rel="stylesheet" href="${path }/resource/zTree/css/demo.css" type="text/css">
	<link rel="stylesheet" href="${path }/resource/zTree/css/metroStyle/metroStyle.css" type="text/css">
	<script type="text/javascript" src="${path }/resource/js/jquery-2.0.3.js"></script>
	<script type="text/javascript" src="${path }/resource/layer/layer.js"></script>
	<script type="text/javascript" src="${path }/resource/zTree/js/jquery.ztree.core.js"></script>
	<script type="text/javascript" src="${path }/resource/zTree/js/jquery.ztree.excheck.js"></script>
	<script type="text/javascript" src="${path }/resource/zTree/js/jquery.ztree.exedit.js"></script>
	<script type="text/javascript" src="${path }/resource/js/mytools.js"></script>
	<SCRIPT type="text/javascript">
	var zTree;
	//创建树型结构
	function createTree() {
		var setting = {
			check: {
				enable: true
			},
			edit: {
				enable: true,
				showRemoveBtn: false,
				showRenameBtn: false
			},
			  async: {
		            enable: true,//设置是否异步加载
		            url:"${path}/developer/fun/all"
		        },
			data: {
				simpleData: {
					enable: true,
					pIdKey: "pId",
	                idKey: "id"
				},
				key: {
                    checked: "CHECKED",
                    name:"name",
                    url:"url"
                }
			},
			callback: {
				onCheck: onCheck
			}
		};
		  zTree = $.fn.zTree.init($("#treeDemo"), setting);   
		  zTree.expandAll(true);
	}
	/*把选中的id展示在文本框  */
	function onCheck(e, treeId, treeNode) {
		nodes = zTree.getCheckedNodes(true),
		v = "";
		for (var i=0, l=nodes.length; i<l; i++) {
			v += nodes[i].id + ",";
		}
		if (v.length > 0 ) v = v.substring(0, v.length-1);
		var ids = $("#fnids");
		ids.attr("value", v);
	}
		$(document).ready(function(){
			createTree();
		});
	</SCRIPT>
</HEAD>

<BODY>
<div class="content_wrap">
	<div class="zTreeDemoBackground left">
		<ul id="treeDemo" class="ztree"></ul>
		<!-- <ul id="log" class="log"></ul> -->
	</div>
		<!--存id的隐藏标签  -->
		<input type="hidden" value="" id="fnids">
		分配给：
		<!--显示的值，value值 ，请求数据地址-->
	<select id="autoselect"
			data-show="userName" 
			data-value="userId" 
			data-url="${path}/developer/user/all" 
			>
	</select>
	
	<input type="button" value="分配" onclick="allot()">
	</div>
	<script type="text/javascript">
	mytooljs.initSelect({idSelecter:"#autoselect"});
	function allot(){
		var userid = $("#autoselect").val();
		var fnids = $("#fnids").val();
		if( fnids==null||userid==null||userid==''||fnids=='' ){
			return false;
		}
		var data = {"userid":userid,"fnids":fnids}
		console.log(data);
		//发送ajax请求
		$.ajax({
  		'type':'post',
  		'url':"${path}/developer/power/addPower",
  		'data':data,
  		'dataType':'json',
  		'success':function(data,status){
  			layer.alert('分配成功!',{icon:1});
  		}
  		});
	}
	</script>
</BODY>
</HTML>